#ifndef SUPER_MENU_H
#define SUPER_MENU_H

#include "PopupMenu.h"

#include <QFrame>
#include "SuperMenuBtn.h"

/**
 * The actions supported by the currently visible view.
 *
 * The menu can be either vertical or horizontal.
 *
 * Typical means Options, Save/Cancel, Cancel, etc.
 *
 * Since the buttons here need to be drawn rotatedly in landscape view, we use WPMenuButtons for them.
 */
class CSuperMenu : public QFrame
{
    Q_OBJECT

public:
    CSuperMenu (QWidget *parent = NULL);

    /** Change menu orientation */
    void setOrientation (Qt::Orientation orientation);

    /** Add a QAction to the list of popup menu items, and return it for convenience */
    QAction * addMenuItem (QAction *action);
    
    // XXX do some proper solution for this...
    enum Softkey {
        PositiveSoftkey,
        NegativeSoftkey,
        SelectSoftkey
    };
    bool ActivateSoftkeyAction(Softkey softkey);

public slots:    
    /** Show a menu item that opens up a popup menu, plus a quit button */
    void showMenuQuit ();

    /** Show a pair of Save/Cancel buttons tied to the given actions */
    void showSaveCancel (QAction *save, QAction *cancel);
    
    /** Show a pair of Save/Exit buttons, save tied to the given action */
    void showSaveExit (QAction *save);

    /** Show a single Back button tied to the given action */
    void showBack (QAction *back);

    /** Display the configured popup menu */
    void showPopupMenu ();

signals:
    /** Application should terminate */
    void exitApplication ();

protected:
    /** Set the list of active buttons */
    void setActiveButtons (const QList<CSuperMenuBtn *> &activeButtons);

    /** Calculate position for popup menu in global coordinates */
    QPoint getPopupMenuPosition ();

    /** Reposition popup menu if open */
    void moveEvent (QMoveEvent *event);
    
private slots:
    void triggerCurrentMenuItem();
    void menuHidden();
    
protected:
    int iCurrentOrientation;

    /* Various default buttons */
    CSuperMenuBtn *iOptionsButton;
    CSuperMenuBtn *iSaveButton;
    CSuperMenuBtn *iCancelButton;
    CSuperMenuBtn *iBackButton;
    CSuperMenuBtn *iExitButton;
    CSuperMenuBtn *iSelectButton;

    /** Menu related actions */
    QAction *iMenuAction;
    QAction *iSelectFromMenuAction;
    QAction *iHideMenuAction;
    
    QAction *iExitAction;

    /** Popup menu to display */
    PopupMenu *iPopupMenu;

    /** Currently active set of buttons */
    QList<CSuperMenuBtn *> iActiveButtons;
    QList<CSuperMenuBtn *> iActiveButtonsBeforeMenu;
};

#endif /* WPMENU_H */
